package com.task.scheduling.job;


import com.task.scheduling.dao.TaskSchedulingDao;
import com.task.scheduling.service.TaskHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: facade-console
 * @description: 更新正在执行任务的心跳数
 * @author: zhouliangliang
 * @create: 2018-11-29 20:32
 **/
@Component
public class HeartbeatJob {

    private Logger log = LoggerFactory.getLogger(HeartbeatJob.class);

    @Autowired
    private TaskSchedulingDao taskSchedulingDao;

    @Scheduled(cron = "0 */1 * * * *")
    public void heartBeat() {
        log.info("更新心跳任务");
        List<Long> idList = TaskHolder.getRunningTaskList();
        for(Long id : idList) {
            taskSchedulingDao.heartBeat(id);
        }
    }
}